<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script src="/html/axios.min.js"></script>
<script src="/html/util.js"></script>
<script>
    window.onload = function (){
        getUserName()
        showProductList()
    }

    function getUserName(){
        axios.get("/user/getUserName",null).then(e => {

            var info = e.data;
            if (info == null || info ==''){
                $('userSpan').innerHTML = "你好，请先<a href='/html/login.html'>登录</a>"
            }else {
                $('userSpan').innerHTML = "欢迎光临"+info.name;
            }
        })
    }
    function showProductList(){
        axios.get("/product/findAll",null).then(e => {
            var info = e.data;
            var str = "";
            for (var i=0;i<info.length;i++){
                str += `<div><img src="/html/img/${info[i].imgPath}" width='200' height="200"><br>
                        ${info[i].name}<br><a href="/html/speak/speak.html?id=${info[i].id}">查看</a></div>`
            }
            $('productDiv').innerHTML = str;
        })
    }
</script>
<body>
    欢迎光临:<span id="userSpan"></span>

    <div style="display: flex" id="productDiv"></div>
</body>
</html>